package com.cxdr.awsips.packing.db;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.mchange.v2.c3p0.ComboPooledDataSource;

public class DBHelper {
	private static ComboPooledDataSource dataSource;
	private static boolean inited = false;

	public static void init() {
		dataSource = new ComboPooledDataSource("oracleds");
		inited = true;
	}

	public void close() {
		dataSource.close();
	}

	public static Connection getConnection() throws SQLException {
		if (!inited) {
			init();
		}
		return dataSource.getConnection();
	}

	public static void main(String args[]) throws SQLException {
		Connection c = DBHelper.getConnection();
		ResultSet rs = c.createStatement().executeQuery(
				"select sysdate from dual");
		if (rs.next()) {
			System.out.println(rs.getString(1));
		}
	}
}
